home *** CD-ROM | disk | FTP | other *** search
-
-
- /*****************************************************************************/
- /* */
- /* AmigaAMP Plugin skeleton v1.2 */
- /* */
- /* Written December 1998 by Thomas Wenzel */
- /* */
- /* Adapted to work with VBCC by Thomas Jensen Jan 1999 */
- /* */
- /*****************************************************************************/
- /* */
- /* This is the basic recommended framework for every AmigaAMP plugin. */
- /* To make it as easy as possible all plugins are normal AmigaDOS */
- /* executables which can be launched and stopped at any time. */
- /* */
- /* This sourcecode and executable are free for non-commercial use only! */
- /* */
- /* Hint: You may use as many printf's or kprintf's as you like for debugging */
- /* purposes. However, before releasing the plugin, please remove all stdio */
- /* and rawio functions and compile with NODEBUG NOSTDIO options set. */
- /* */
- /*****************************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <math.h>
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
-
- #include <dos/dostags.h>
- #include <graphics/gfxbase.h>
-
- #include "trackinfo.h"
-
- BOOL PluginInit(void);
- void PluginExit(void);
- void PluginLoop(void);
- void ShowRequester(char *Text, char *Button);
-
- /***************************************************************************/
- /* This is the global variables section. Don't change anything here unless */
- /* you know what you're doing! */
- /***************************************************************************/
-
- BYTE PluginSignal;
- ULONG PluginMask;
- BOOL Accepted;
- struct Process *PluginTask;
- struct MsgPort *PluginMP;
- struct MsgPort *PluginRP;
- BYTE InfoSignal; // v1.2
- ULONG InfoMask; // v1.2
- struct TrackInfo *tinfo; // v1.2
-
- UWORD *PluginRawL;
- UWORD *PluginRawR;
- UWORD *SpecRawL;
- UWORD *SpecRawR;
-
- struct PluginMessage {
- struct Message msg;
- ULONG PluginMask;
- struct Process *PluginTask;
- UWORD **SpecRawL;
- UWORD **SpecRawR;
- BOOL Accepted;
-
- /* All data beyond this point is new for v1.2. */
- /* AmigaAMP v2.5 and up will detect this new data and act accordingly. */
- /* Older versions of AmigaAMP will simply ignore it. */
-
- ULONG InfoMask;
- struct TrackInfo **tinfo;
- ULONG reserved;
- };
-
- /***************************************************************************/
- /* This is the main part. Again, don't change anything here if you haven't */
- /* got a very good reason to do so! */
- /***************************************************************************/
-
- int main(void) {
- struct PluginMessage *PluginMsg;
- struct PluginMessage *ReplyMsg;
-
- /* (TJ) added for VBCC compatibility */
- #ifndef __SASC
- IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 36);
- if(IntuitionBase == NULL) {
- printf("Unable to open intuition.library V36+ (OS 2.1 required)\n");
- exit(5);
- }
- #endif
-
- /* Allocate all user resources */
- if(PluginInit()) {
- /* Check if a plugin capable instance of AmigaAMP is running */
- if(PluginMP=FindPort("AmigaAMP plugin port")) {
- /* Allocate a sigbit for receiving signals FROM AmigaAMP */
- PluginTask = (struct Process *)FindTask(NULL);
- PluginSignal = AllocSignal(-1);
- InfoSignal = AllocSignal(-1); // v1.2
- if(PluginSignal != -1 && InfoSignal != -1) { // v1.2
- InfoMask = 1L << InfoSignal; // v1.2
- PluginMask = 1L << PluginSignal;
-
- /* Allocate a message and reply port for sending messages TO AmigaAMP */
- PluginMsg=AllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
- PluginRP=CreatePort(0,0);
-
- /* Tell AmigaAMP all the details it needs to know */
- PluginMsg->msg.mn_Node.ln_Type = NT_MESSAGE;
- PluginMsg->msg.mn_Length = sizeof(struct PluginMessage);
- PluginMsg->msg.mn_ReplyPort = PluginRP;
- PluginMsg->PluginMask = PluginMask;
- PluginMsg->PluginTask = PluginTask;
- PluginMsg->SpecRawL = &SpecRawL;
- PluginMsg->SpecRawR = &SpecRawR;
- PluginMsg->InfoMask = InfoMask; // v1.2
- PluginMsg->tinfo = &tinfo; // v1.2
- PluginMsg->reserved = 0; // v1.2
- PutMsg(PluginMP, (struct Message *)PluginMsg);
- /* Wait for a reply */
- WaitPort(PluginRP);
- /* Let's see if AmigaAMP accepted our registration attempt */
- if(ReplyMsg = (struct PluginMessage *)GetMsg(PluginRP)) Accepted=ReplyMsg->Accepted;
- else Accepted=FALSE;
-
- if(Accepted) {
- /* If it did, start the plugin loop */
- PluginLoop();
-
- /* Tell AmigaAMP that this plugin is going down */
- PluginMsg->PluginMask = 0; /* (TJ) changed from NULL for VBCC compatibility */
- PluginMsg->PluginTask = NULL;
- PluginMsg->SpecRawL = NULL;
- PluginMsg->SpecRawR = NULL;
- PluginMsg->InfoMask = 0; // v1.2
- PluginMsg->tinfo = NULL; // v1.2
- PluginMsg->reserved = 0; // v1.2
- PutMsg(PluginMP, (struct Message *)PluginMsg);
- /* Wait for confirmation before going on! */
- WaitPort(PluginRP);
- GetMsg(PluginRP);
- /* Now that AmigaAMP knows that we're gone, we can quit */
- }
- else {
- /* If AmigaAMP didn't accept us, tell the user about it */
- ShowRequester("Plugin rejected by AmigaAMP!\nPerhaps there's another one running.", "Abort");
- }
-
- /* Free all resources */
- FreeVec(PluginMsg);
- DeletePort(PluginRP);
- if(PluginSignal != -1) FreeSignal(PluginSignal);
- if(InfoSignal != -1) FreeSignal(InfoSignal); // v1.2
- }
- else {
- ShowRequester("Signal allocation failure!", "Abort");
- }
- }
- else {
- ShowRequester("Could not find message port!\nAmigaAMP probably not running.", "Abort");
- }
- }
- else {
- ShowRequester("Plugin initialisation failed!", "Ok");
- }
- /* Free all user resources */
- PluginExit();
-
- /* added for VBCC compatibility */
- #ifndef __SASC
- if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
- #endif
- return(0);
- }
-
- /*****************************************************************************/
- /* Ok, now for the individual plugin sourcecode. */
- /* Just like before, we start with the global variables section */
- /*****************************************************************************/
-
-
-
- /****************************************************************************/
- /* This function will be called once when the plugin is started. You should */
- /* allocate all needed resources here. Return TRUE if all went well. */
- /****************************************************************************/
-
- BOOL PluginInit(void) {
- /* Initialise everything here. Return TRUE if all went well, FALSE otherwise */
- return(TRUE);
- }
-
- /******************************************************************************/
- /* This function will be called when the plugin is shut down. You should free */
- /* all previously allocated resources here. */
- /******************************************************************************/
-
- void PluginExit(void) {
- /* Free everything you've allocated before */
- }
-
- /*******************************************************************************/
- /* This is the main Plugin Loop. It will receive a signal matching PluginMask */
- /* each time new spectral data is ready. The data is stored in two arrays, */
- /* UWORD SpecRawL[512] and UWORD SpecRawR[512]. The scale is logarithmic, i.e. */
- /* 0 means below -96dB, 65535 means 0dB. */
- /* No matter how long it takes until your plugin actually processes the data, */
- /* the memory referenced by the array pointers always remains valid! */
- /* */
- /* Your plugin loop MUST quit when it receives SIGBREAKF_CTRL_C. If you've */
- /* opened a window you should react to the close gadget as well. For full */
- /* screen plugins I strongly recommend checking the ESC key. */
- /*******************************************************************************/
-
- void PluginLoop(void) {
- ULONG Signals;
-
- for(;;) {
-
- /* Wait until there's something to do */
- Signals=Wait(SIGBREAKF_CTRL_C | PluginMask | InfoMask); // v1.2
-
- /* Break received -> quit at once! */
- if(Signals & SIGBREAKF_CTRL_C) break;
-
-
- /* New data has arrived! */
- if(Signals & PluginMask) {
- /*********************************************************/
- /* Visualise SpecRawL[0..511] and SpecRawR[0..512] here! */
- /*********************************************************/
- }
-
- /* New track info has arrived! */
- if(Signals & InfoMask) {
- /**********************************************************************/
- /* If you want to display anything from struct TrackInfo, do it here! */
- /**********************************************************************/
- }
- }
- }
-
- void ShowRequester(char *Text, char *Button) {
- struct EasyStruct Req;
-
- Req.es_Title = "AmigaAMP Plugin";
- Req.es_TextFormat = (UBYTE*)Text;
- Req.es_GadgetFormat = (UBYTE*)Button;
- EasyRequestArgs(NULL, &Req, NULL, NULL);
- }
-
-
- /* (TJ) added to avoid VBCC linker error */
- #ifndef __SASC
- struct IntuitionBase *IntuitionBase=NULL;
- #endif
-
-